﻿// /////////////////////////////////////////////////////////////////////
// 
//  Codeplex JSAnalyse
//  Copyright (c) 2011
//  JSAnalyse.Core   JavascriptFileInfo.cs
// 
// /////////////////////////////////////////////////////////////////////
namespace JSAnalyse.Core
{
    /// <summary>
    /// Javascript files info container
    /// </summary>
    public class JavascriptFileInfo
    {
        #region Public properties

        /// <summary>
        /// Gets or sets the name of the file.
        /// </summary>
        /// <value>The name of the file.</value>
        public string File { get; set; }

        /// <summary>
        /// Gets or sets the content of the file.
        /// </summary>
        /// <value>The content of the file.</value>
        public string FileContent { get; private set; }

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="JavascriptFileInfo"/> class.
        /// </summary>
        /// <param name="file">The file.</param>
        public JavascriptFileInfo(string file)
        {
            File = file;
            FileContent = GetFileContent(file);
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="JavascriptFileInfo"/> class.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="fileContent">Content of the file.</param>
        /// <remarks></remarks>
        public JavascriptFileInfo(string file, string fileContent)
        {
            File = file;
            FileContent = fileContent;
        }

        #endregion

        /// <summary>
        /// Reads the content of the given file
        /// </summary>
        /// <param name="file">The file.</param>
        /// <returns>content of the file</returns>
        /// <remarks></remarks>
        private string GetFileContent(string file)
        {
            var result = string.Empty;
            if (System.IO.File.Exists(file))
            {
                result = System.IO.File.ReadAllText(file);
            }
            return result;
        }
    }
}
